package cn.bdqn.controller;

import cn.bdqn.pojo.Grade;
import cn.bdqn.pojo.PageInfo;
import cn.bdqn.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 正文
 * @date 2020/7/16 - 16:37
 */
@Controller
public class GradeController {
    @Autowired
    private GradeService gradeService;


//    public String list(Model model) {
//        List<Employees> list=gradeService.getList();
//        System.out.println("asd"+list);
//        model.addAttribute("list999",list);
//        return "personal/userList";
//    }
    //我的成绩
    @RequestMapping("/Gradelist")
    public String gradelist(HttpServletRequest request,Model model,@RequestParam(name = "pn",defaultValue = "1") Integer pn){
//        List<Grade> en=gradeService.findGradeAll(grade);
//        request.getSession().setAttribute("gradelist",en);
//        return "personal/userList";
        Integer id = (Integer) request.getSession().getAttribute("id");
        List<Grade> emps = null;
        if(pn <= 1){
            emps = gradeService.getEmps(id,0);
        }else{
            emps = gradeService.getEmps(id,(pn-1)*3);
        }
        PageInfo pageInfo = new PageInfo(pn);
        pageInfo.setTotal(gradeService.getCount(id));
        pageInfo.setEmps(emps);
        model.addAttribute("pageInfo",pageInfo);
        request.getSession().setAttribute("gradelist",pageInfo);
        return "personal/userList";
    }
}
